<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Admin\Controllers;

use App\Models\WithdrawCashSetting;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;

class WithdrawCashSettingController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new WithdrawCashSetting(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('explanation');
            $grid->column('fee');
            $grid->column('bean');
            $grid->column('transfer_others_fee');
            $grid->column('transfer_others_bean');
            $grid->column('transfer_wallet_fee');
            $grid->column('transfer_wallet_bean');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->between('created_at', '创建时间')->datetime();
                $filter->between('updated_at', '修改时间')->datetime();
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WithdrawCashSetting(), function (Show $show) {
            $show->field('id');
            $show->field('explanation');
            $show->field('fee');
            $show->field('bean');
            $show->field('transfer_others_fee');
            $show->field('transfer_others_bean');
            $show->field('transfer_wallet_fee');
            $show->field('transfer_wallet_bean');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WithdrawCashSetting(), function (Form $form) {
            $form->display('id');
            $form->editor('explanation');
            $form->rate('fee');
            $form->rate('bean');
            $form->rate('transfer_others_fee');
            $form->rate('transfer_others_bean');
            $form->rate('transfer_wallet_fee');
            $form->rate('transfer_wallet_bean');
            $form->number('contribution_value', '消耗贡献值');

            $form->display('created_at');
            $form->display('updated_at');
            $form->saved(function (Form $form) {
                return $form->response()->success('操作成功')->redirect(request()->fullUrl() . '/edit');
            });
        });
    }
}
